/*
 * FileVideoSource.cpp
 *
 *  Created on: 2018年3月19日
 *      Author: zhengboyuan
 */

#include "FileVideoSource.h"
#include "Path.h"

FileVideoSource::FileVideoSource():
	m_size(720, 576)
{
}

FileVideoSource::~FileVideoSource()
{
}

void FileVideoSource::setSize(const cv::Size& size)
{
	if (size.width > 0 && size.height > 0)
	{
		m_size = size;
	}
}

cv::Size FileVideoSource::getSize()
{
	return m_size;
}

bool FileVideoSource::getFrame(cv::Mat& frame)
{
	cv::Mat mat = cv::imread(m_filepath);
	if (mat.empty())
	{
		return false;
	}

	if (mat.size() == m_size)
	{
		frame = mat;
	}
	else
	{
		cv::resize(mat, frame, m_size);
	}
	
	return true;
}

bool FileVideoSource::isOpened()
{
	return comn::Path::exist(m_filepath);
}

void FileVideoSource::setPath(const char* filepath)
{
	m_filepath = filepath;
}

